﻿using RayDen.Library.Core.Primitives;

namespace PathEngine
{
    public class Radiance
    {
        protected SampledSpectrum spectra;

        public Radiance()
        {
            spectra = SampledSpectrum.ZeroSpectrum();
        }

        public Radiance(float f)
        {
            spectra = new SampledSpectrum(f);
        }

        public Radiance(ref RgbSpectrum s, SpectrumType t)
        {
            spectra = new SampledSpectrum(ref s, t);
        }

        #region Operations

        public Radiance Add(float f)
        {
            spectra = spectra + f;
            return this;
        }

        public Radiance Mul(float f)
        {
            spectra = spectra * f;
            return this;
        }

        public Radiance Add(ref RgbSpectrum f, SpectrumType type)
        {
            spectra = spectra + new SampledSpectrum(ref f, type);
            return this;
        }

        public Radiance Mul(ref RgbSpectrum f, SpectrumType type)
        {
            spectra = spectra * new SampledSpectrum(ref f, type);
            return this;
        }
        public Radiance Add(RgbSpectrum f, SpectrumType type)
        {
            spectra = spectra + new SampledSpectrum(ref f, type);
            return this;
        }

        public Radiance Mul(RgbSpectrum f, SpectrumType type)
        {
            spectra = spectra * new SampledSpectrum(ref f, type);
            return this;
        }

        public Radiance Add(ref SampledSpectrum f)
        {
            spectra = spectra + f;
            return this;
        }

        public Radiance Mul(ref SampledSpectrum f)
        {
            spectra = spectra * f;
            return this;
        }
        #endregion

        public void GetRGB(out float[] rgb)
        {
            spectra.ToRGB(out rgb);
        }

        public void GetRgbSpectrum(out RgbSpectrum rgb)
        {
            rgb = spectra.ToRgb();
        }
    }
}